/*
 * ItemGUI2.java
 *
 * Created on July 29, 2007, 5:43 PM
 *
 * @author  Truben
 */

package no.truben.dbox.GUI.windows;

import no.truben.dbox.util.BrowserControl;
import no.truben.dbox.model.ApplicationBean;
import no.truben.dbox.*;
import no.truben.dbox.util.FileChooserFilter;
import no.truben.dbox.util.onlineresource.TrubenResource;
import no.truben.dbox.util.HelperClass;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import javax.imageio.ImageIO;
import javax.imageio.stream.ImageInputStream;
import javax.swing.*;
import nl.ikarus.nxt.priv.imageio.icoreader.obj.ICOFile;
import nl.ikarus.nxt.priv.imageio.icoreader.obj.IconEntry;
import no.truben.dbox.GUI.windows.listRenderers.ExpertListRenderer;
import no.truben.dbox.util.Constants;

public class EditApplication extends javax.swing.JDialog {
    
    private ApplicationBean dos;
    private MainWindow g;
    
    public EditApplication(MainWindow parent) {
        dos = new ApplicationBean();

        g = parent;
        setModal(true);
        initComponents();
        createYearList("1990");
        cmbGenre.setModel(new javax.swing.DefaultComboBoxModel(Main.pref.getGenres()));
        cmbGenre.setSelectedItem(dos.getGenre());
        centerScreen();
    }
    
    public EditApplication(ApplicationBean di, MainWindow parent) {
        dos = di;
        initComponents();
        cmbGenre.setModel(new javax.swing.DefaultComboBoxModel(Main.pref.getGenres()));
        centerScreen();
        setModal(true);
        
        createYearList(dos.getYear());

        g = parent;
        appName.setText(dos.getName());
        appExec.setText(dos.getGame());
        appPath.setText(dos.getPath());
        appSetup.setText(dos.getInstaller());
        appIcon.setText(dos.getIcon());
        appCD.setText(dos.getCdrom());
        sldCycles.setValue(dos.getCycles());
        appFrameSkip.setValue(dos.getFrameskip());
        chkFavorite.setSelected(dos.isStar());
        cmbGenre.setSelectedItem(dos.getGenre());
        txtKeywords.setText(dos.getKeywords());
        txtDeveloper.setText(dos.getDeveloper());
        txtPublisher.setText(dos.getPublisher());
        cdromDriveLetter.setSelectedItem(dos.getCdromLetter());


        if(!dos.getExtra().equals("")) {
            String[] s = dos.getExtra().substring(0, dos.getExtra().length()-1).split(";");
            JList lm = new JList(s);
            listProperties.setModel(lm.getModel());
        }
    }

    private void createYearList(String year) {
        String[] years = new String[42];
        years[0] = "";
        for(int i = 1; i < 40; i++)
            years[i] = "" + (2011 - i);

        int place = -1;

        for(int i = 0; i < years.length; i++)
            if(years[i].equals(year)) {
                place = i;
                break;
            }

        if(place == -1) {
            years[years.length-1] = year;
            place = years.length-1;
        }

        cmbYear.setModel(new DefaultComboBoxModel(years));

        cmbYear.setSelectedIndex(place);
    }
    
    /**
     * Putter boksen midt paa skjermen
     */
    public void centerScreen() {
    	  Dimension dimension = getToolkit().getScreenSize();
    	  Rectangle abounds = getBounds();
    	  setLocation((dimension.width - abounds.width) / 2,
    	      (dimension.height - abounds.height) / 2);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cmdConfirm = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel(){
            ImageIcon backImage = new javax.swing.ImageIcon(Main.theme.getBackgroundImage());
            Image image = backImage.getImage();
            int w = backImage.getIconWidth();

            public void paintComponent (Graphics g) {
                for(int i=0;i<100;i++)
                g.drawImage(image, w*i, 0, this);
                super.paintComponent(g);
            }
        }
        ;
        jLabel5 = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        appName = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        appExec = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        appIcon = new javax.swing.JTextField();
        jButton4 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        sldCycles = new javax.swing.JSlider();
        jButton6 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        appSetup = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        appPath = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        appCD = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        appFrameSkip = new javax.swing.JSpinner();
        jButton5 = new javax.swing.JButton();
        jLabel18 = new javax.swing.JLabel();
        cdromDriveLetter = new javax.swing.JComboBox();
        jPanel4 = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        cmbGenre = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        chkFavorite = new javax.swing.JCheckBox();
        txtKeywords = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        cmbYear = new javax.swing.JComboBox();
        jLabel16 = new javax.swing.JLabel();
        txtDeveloper = new javax.swing.JTextField();
        txtPublisher = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        listProperties = new javax.swing.JList();
        cmdAdd = new javax.swing.JButton();
        cmdRemove = new javax.swing.JButton();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jButton7 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setModal(true);
        setResizable(false);

        cmdConfirm.setText("OK");
        cmdConfirm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdConfirmActionPerformed(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setOpaque(false);

        jLabel5.setFont(new java.awt.Font("Lucida Grande", 2, 18));
        jLabel5.setForeground(new java.awt.Color(255, 255, 255));
        jLabel5.setText("Edit Game");

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel5)
                .addContainerGap(520, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(20, Short.MAX_VALUE)
                .add(jLabel5)
                .add(14, 14, 14))
        );

        jPanel2.setOpaque(false);

        jLabel1.setText("Name");

        appName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                appNameActionPerformed(evt);
            }
        });

        jLabel3.setText("Executable");

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/no/truben/dbox/img/folder.png"))); // NOI18N
        jButton1.setToolTipText("Browse...");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel8.setText("Icon");

        appIcon.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                appIconCaretUpdate(evt);
            }
        });
        appIcon.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                appIconActionPerformed(evt);
            }
        });
        appIcon.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
            }
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
                appIconCaretPositionChanged(evt);
            }
        });
        appIcon.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                appIconPropertyChange(evt);
            }
        });

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/no/truben/dbox/img/folder.png"))); // NOI18N
        jButton4.setToolTipText("Browse...");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jLabel6.setText("How fast would you like the computer?");
        jLabel6.setToolTipText("How fast should the emulated\ncomputer be? If you draw the slider\nto the left, it will be slower, and to\nthe right it will be faster");

        sldCycles.setMaximum(25000);
        sldCycles.setMinimum(1);
        sldCycles.setToolTipText("3000 CPU Cycles");
        sldCycles.setValue(3000);
        sldCycles.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                sldCyclesMousePressed(evt);
            }
        });
        sldCycles.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                sldCyclesStateChanged(evt);
            }
        });
        sldCycles.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                sldCyclesPropertyChange(evt);
            }
        });

        jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/no/truben/dbox/img/image-x-generic.png"))); // NOI18N
        jButton6.setToolTipText("Preview");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, appName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 542, Short.MAX_VALUE)
                    .add(jLabel1)
                    .add(jLabel3)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
                        .add(appExec, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 503, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jButton1))
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(appIcon, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 450, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jButton4)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 21, Short.MAX_VALUE)
                        .add(jButton6))
                    .add(jLabel8)
                    .add(jLabel6)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, sldCycles, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 542, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(appName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 23, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jLabel3)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(appExec, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jButton1))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(jLabel8)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(appIcon, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jButton6)
                    .add(jButton4))
                .add(18, 18, 18)
                .add(jLabel6)
                .add(sldCycles, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(218, 218, 218))
        );

        jTabbedPane1.addTab("General", jPanel2);

        jPanel3.setOpaque(false);

        jLabel4.setText("Setup");

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/no/truben/dbox/img/folder.png"))); // NOI18N
        jButton2.setToolTipText("Browse...");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel2.setText("Path");

        jLabel7.setText("CD-ROM Directory");

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/no/truben/dbox/img/folder.png"))); // NOI18N
        jButton3.setToolTipText("Browse...");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel9.setText("How many frames DOSBox skips before drawing one: ");
        jLabel9.setToolTipText("Frameskip");

        appFrameSkip.setModel(new javax.swing.SpinnerNumberModel(0, 0, 9, 1));

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/no/truben/dbox/img/format-text-bold.png"))); // NOI18N
        jButton5.setToolTipText("Set CD-ROM label");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jLabel18.setText("Drive Letter");

        cdromDriveLetter.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V" }));
        cdromDriveLetter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cdromDriveLetterActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(appPath, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 542, Short.MAX_VALUE)
                    .add(jPanel3Layout.createSequentialGroup()
                        .add(appSetup, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 503, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jButton2))
                    .add(jPanel3Layout.createSequentialGroup()
                        .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel3Layout.createSequentialGroup()
                                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jLabel2)
                                    .add(jLabel4)
                                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel3Layout.createSequentialGroup()
                                        .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                            .add(jPanel3Layout.createSequentialGroup()
                                                .add(jLabel7)
                                                .add(201, 201, 201))
                                            .add(jPanel3Layout.createSequentialGroup()
                                                .add(appCD, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 390, Short.MAX_VALUE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)))
                                        .add(jButton3)
                                        .add(4, 4, 4)))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jButton5))
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel9, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 465, Short.MAX_VALUE))
                        .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jPanel3Layout.createSequentialGroup()
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(appFrameSkip, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel3Layout.createSequentialGroup()
                                .add(4, 4, 4)
                                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(cdromDriveLetter, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jLabel18))))))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 14, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(appPath, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 23, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jPanel3Layout.createSequentialGroup()
                        .add(jLabel4)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(appSetup, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jButton2))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jPanel3Layout.createSequentialGroup()
                        .add(jLabel7)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(appCD, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(3, 3, 3))
                    .add(jPanel3Layout.createSequentialGroup()
                        .add(jLabel18)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(cdromDriveLetter, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jButton5)
                    .add(jButton3))
                .add(18, 18, 18)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel9)
                    .add(appFrameSkip, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(54, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Advanced", jPanel3);

        jPanel4.setOpaque(false);

        jLabel10.setLabelFor(cmbGenre);
        jLabel10.setText("Genre:");

        jLabel11.setLabelFor(txtKeywords);
        jLabel11.setText("Keywords (separate by spaces):");

        chkFavorite.setText("Mark as favorite");

        jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/no/truben/dbox/img/emblem-favorite.png"))); // NOI18N

        jLabel15.setLabelFor(cmbGenre);
        jLabel15.setText("Year:");

        jLabel16.setText("Developer:");

        txtDeveloper.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtDeveloperActionPerformed(evt);
            }
        });

        jLabel17.setText("Publisher:");

        org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel4Layout.createSequentialGroup()
                        .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel10)
                            .add(cmbGenre, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 165, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jLabel16)
                            .add(txtDeveloper, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 253, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 36, Short.MAX_VALUE)
                        .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jPanel4Layout.createSequentialGroup()
                                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(cmbYear, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jLabel17)
                                    .add(jLabel15))
                                .add(153, 153, 153))
                            .add(txtPublisher, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 253, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(jPanel4Layout.createSequentialGroup()
                        .add(chkFavorite)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jLabel12))
                    .add(txtKeywords, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 542, Short.MAX_VALUE)
                    .add(jPanel4Layout.createSequentialGroup()
                        .add(jLabel11)
                        .add(338, 338, 338)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .add(20, 20, 20)
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel4Layout.createSequentialGroup()
                        .add(jLabel10)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(cmbGenre, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel4Layout.createSequentialGroup()
                        .add(jLabel15)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(cmbYear, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jPanel4Layout.createSequentialGroup()
                        .add(jLabel17)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(txtPublisher, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel4Layout.createSequentialGroup()
                        .add(jLabel16)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(txtDeveloper, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jLabel11)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(txtKeywords, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(chkFavorite)
                    .add(jLabel12))
                .addContainerGap(38, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Meta Information", jPanel4);

        jPanel5.setOpaque(false);

        listProperties.setFont(new java.awt.Font("Courier", 0, 12));
        listProperties.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        listProperties.setCellRenderer(new ExpertListRenderer());
        jScrollPane1.setViewportView(listProperties);

        cmdAdd.setText("+");
        cmdAdd.setToolTipText("Add Dosbox property");
        cmdAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdAddActionPerformed(evt);
            }
        });

        cmdRemove.setText("-");
        cmdRemove.setToolTipText("Remove selected Dosbox property");
        cmdRemove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdRemoveActionPerformed(evt);
            }
        });

        jLabel13.setText("DosBox properties");

        jLabel14.setForeground(new java.awt.Color(51, 51, 255));
        jLabel14.setText("Learn more...");
        jLabel14.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel14MouseClicked(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel5Layout = new org.jdesktop.layout.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 542, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel5Layout.createSequentialGroup()
                        .add(jLabel14)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 304, Short.MAX_VALUE)
                        .add(cmdAdd)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(cmdRemove))
                    .add(jLabel13))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel5Layout.createSequentialGroup()
                .add(20, 20, 20)
                .add(jLabel13)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(cmdRemove)
                    .add(cmdAdd)
                    .add(jLabel14))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Expert", jPanel5);

        jButton7.setText("Resolve");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap(438, Short.MAX_VALUE)
                .add(jButton7)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(cmdConfirm, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 76, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 603, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 320, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(cmdConfirm)
                    .add(jButton7))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void sldCyclesStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_sldCyclesStateChanged
    
    sldCycles.setToolTipText(sldCycles.getValue()+" CPU Cycles");
}//GEN-LAST:event_sldCyclesStateChanged

private void sldCyclesPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_sldCyclesPropertyChange
    
}//GEN-LAST:event_sldCyclesPropertyChange


private void cmdConfirmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdConfirmActionPerformed
    ApplicationBean d = new ApplicationBean();

    // Set prefrences
    d.setName(appName.getText());
    d.setPath(appPath.getText());
    d.setInstaller(appSetup.getText());
    d.setCycles(sldCycles.getValue());
    d.setCdrom(appCD.getText());
    d.setGame(appExec.getText());
    d.setFrameskip(Integer.parseInt(appFrameSkip.getValue().toString()));
    d.setStar(chkFavorite.isSelected());
    d.setIcon(appIcon.getText());
    d.setKeywords(txtKeywords.getText());
    d.setGenre(cmbGenre.getSelectedItem().toString());
    d.setExtra(stringifyModel(listProperties.getModel()));
    d.setCdromLabel(dos.getCdromLabel());
    d.setUniqueID(dos.getUniqueID());
    d.setDeveloper(txtDeveloper.getText());
    d.setPublisher(txtPublisher.getText());
    d.setYear(cmbYear.getSelectedItem().toString());
    d.setCdromLetter(cdromDriveLetter.getSelectedItem().toString());

    MainWindow.bl.addGame(d);
    this.setVisible(false);
}//GEN-LAST:event_cmdConfirmActionPerformed

private String stringifyModel(ListModel listmodel){
    String output = "";
    for(int i = 0; i < listmodel.getSize(); i++) {
        output += listmodel.getElementAt(i) + ";";
    }
    return output;
}

private void appNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_appNameActionPerformed
    
}//GEN-LAST:event_appNameActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    String s;
    if(!appPath.getText().equals(""))
        s = HelperClass.showFileChooser(this, "Select file",
            new FileChooserFilter(FileChooserFilter.EXTENSIONS, new String[]{".exe",".com",".bat"},
            "Executable DOS files (*.exe, *.com, *.bat)"), false, appPath.getText());
    else
        s = HelperClass.showFileChooser(this, "Select file",
                new FileChooserFilter(FileChooserFilter.EXTENSIONS, new String[]{".exe",".com",".bat"},
                "Executable DOS files (*.exe, *.com, *.bat)"), false);
    
    if (s != null) {
        int last = 0;
        for(int i = s.length()-1; i >= 0; i--)
            if(s.charAt(i) == File.separatorChar) {
                last = i;
                break;
            }
        appPath.setText(s.substring(0,last));
        appExec.setText(s.substring(last+1));
    }
}//GEN-LAST:event_jButton1ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    String s;
    if(!appPath.getText().equals(""))
        s = HelperClass.showFileChooser(this, "Select file",
            new FileChooserFilter(FileChooserFilter.EXTENSIONS, new String[]{".exe",".com",".bat"},
            "Executable DOS files (*.exe, *.com, *.bat)"), false, appPath.getText());
    else
        s = HelperClass.showFileChooser(this, "Select file",
                new FileChooserFilter(FileChooserFilter.EXTENSIONS, new String[]{".exe",".com",".bat"},
                "Executable DOS files (*.exe, *.com, *.bat)"), false);
    
    if (s != null) {
        int last = 0;
        for(int i = s.length()-1; i >= 0; i--)
            if(s.charAt(i) == File.separatorChar) {
                last = i;
                break;
            }
        System.out.println(s);
        appSetup.setText(s.substring(last+1));
    }
}//GEN-LAST:event_jButton2ActionPerformed



private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    String s;
    if(appPath.getText().equals(""))
        s = HelperClass.showFileChooser(this, "Select directory",
            new FileChooserFilter(FileChooserFilter.DIRECTORIES, null,
            "Directories"), true);
    else
        s = HelperClass.showFileChooser(this, "Select directory",
            new FileChooserFilter(FileChooserFilter.DIRECTORIES, null,
            "Directories"), true,appPath.getText());

    if (s != null) {
        appCD.setText(s);
    }
}//GEN-LAST:event_jButton3ActionPerformed

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
    String s;
    if(appPath.getText().equals(""))
        s = HelperClass.showFileChooser(this, "Select file",
            new FileChooserFilter(FileChooserFilter.EXTENSIONS,
            new String[]{".gif",".ico",".png",".jpg"},
            "Icon files (*.ico, *.gif, *.png, *.jpg)"), false);
    else
        s = HelperClass.showFileChooser(this, "Select file",
            new FileChooserFilter(FileChooserFilter.EXTENSIONS,
            new String[]{".gif",".ico",".png",".jpg"},
            "Icon files (*.ico, *.gif, *.png, *.jpg)"), false, appPath.getText());
    
    if (s != null) {
        appIcon.setText(s);
    }
}//GEN-LAST:event_jButton4ActionPerformed

private void appIconPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_appIconPropertyChange

}//GEN-LAST:event_appIconPropertyChange

private void appIconCaretPositionChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_appIconCaretPositionChanged

}//GEN-LAST:event_appIconCaretPositionChanged

private void appIconActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_appIconActionPerformed

}//GEN-LAST:event_appIconActionPerformed

private void appIconCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_appIconCaretUpdate
    appIconPropertyChange(null);
}//GEN-LAST:event_appIconCaretUpdate

private void cmdAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdAddActionPerformed
    HashMap<String,HashMap<String,String>> values = new HashMap<String,HashMap<String,String>>();
    HashMap<String,String> cpu = new HashMap<String,String>();
    HashMap<String,String> dos = new HashMap<String,String>();
    HashMap<String,String> dosbox = new HashMap<String,String>();
    HashMap<String,String> renderer = new HashMap<String,String>();
    HashMap<String,String> sdl = new HashMap<String,String>();
    HashMap<String,String> ipx = new HashMap<String,String>();
    HashMap<String,String> serial = new HashMap<String,String>();
    
    cpu.put("core", "simple | normal | full | dynamic | auto");
    cpu.put("cputype", "auto | 386 | 386_slow | 486_slow | pentium_slow | 386_prefetch");
    cpu.put("cycles", "[number] | max | auto");
    cpu.put("cycleup", "[number]");
    cpu.put("cycledown", "[number]");
    
    serial.put("serial1", "device [parameter:value]");
    serial.put("serial2", "device [parameter:value]");
    serial.put("serial3", "device [parameter:value]");
    serial.put("serial4", "device [parameter:value]");
    serial.put("serial5", "device [parameter:value]");
    serial.put("serial6", "device [parameter:value]");
    serial.put("serial7", "device [parameter:value]");
    serial.put("serial8", "device [parameter:value]");
    serial.put("serial9", "device [parameter:value]");
    
    ipx.put("ipx", "true | false");
    
    dos.put("xms", "true | false");
    dos.put("ems", "true | false");
    dos.put("umb", "true | false");
    dos.put("keyboardlayout", "auto | none | XY");
    
    renderer.put("frameskip", "[number]");
    renderer.put("aspect", "true | false");
    renderer.put("scaler", "normal2x | normal3x | advmame2x | advmame3x | advinterp2x | advinterp3x | tv2x | tv3x | rgb2x | rgb3x | scan2x | scan3x");
    
    dosbox.put("language", "path-to-language-file");
    dosbox.put("memsize", "[number]");
    dosbox.put("machine", "hercules | cga | tandy | cga | tandy | pcjr | ega | vgaonly | svga_s3 | svga_et3000 | svga_et4000 | svga_paradise | vesa_nolfb | vesa_oldvbe");
    dosbox.put("captures", "path-to-capture-directory");
    
    sdl.put("fullscreen", "true | false");
    sdl.put("fulldouble", "true | false ");
    sdl.put("fullresolution", "width x height | original");
    sdl.put("windowresolution", "width x height | original");
    sdl.put("output", "surface | overlay | opengl | openglnb | ddraw");
    sdl.put("autolock", "true | false");
    sdl.put("sensitivity", "A number from 1 to 1000");
    sdl.put("waitonerror", "true | false");
    sdl.put("priority", "when-focused,when-minimzed");
    sdl.put("mapperfile", "path-to-mapper-file");
    sdl.put("usescancodes", "true | false");

    values.put("AUTOEXEC", null);
    values.put("SDL", sdl);
    values.put("DOSBOX", dosbox);
    values.put("RENDER", renderer);
    values.put("DOS", dos);
    values.put("IPX", ipx);
    values.put("SERIAL", serial);
    values.put("CPU", cpu);
    values.put("MIXER", new HashMap<String,String>());
    values.put("MIDI", new HashMap<String,String>());
    values.put("SBLASTER", new HashMap<String,String>());
    values.put("GUS", new HashMap<String,String>());
    values.put("SPEAKER", new HashMap<String,String>());
    values.put("JOYSTICK", new HashMap<String,String>());

    int i = 0;
    String[] sections = new String[values.size()];
    for(String s : values.keySet())
        sections[i++] = s;

    Arrays.sort(sections);

    String section = (String) JOptionPane.showInputDialog(this, "Please choose a section: ", "Choose section", JOptionPane.QUESTION_MESSAGE, null, sections, sections[0]);
    if(section == null)
                return;

    if(values.get(section) == null)
        addProperties(section, getString("Enter command"), null);
    else {
        HashMap<String,String> properties = values.get(section);
        if( properties.isEmpty() ) {
            String name  = getString("Enter attribute name: ");
            if(name == null)
                return;
            String value = getString("Enter attribute value: ");
            if(name == null)
                return;
            addProperties(section, name, value);
        }
        else {
            i = 0;
            String[] propertyArray = new String[properties.size()];
            for(String s : properties.keySet())
                propertyArray[i++] = s;
            Arrays.sort(propertyArray);
            String name = (String) JOptionPane.showInputDialog(this, "Please choose a property: ", "Choose property", JOptionPane.QUESTION_MESSAGE, null, propertyArray, propertyArray[0]);
            String value;
            if(name == null)
                    return;
            if(properties.get(name).equals("true | false")) {
                value = (String) JOptionPane.showInputDialog(this, "Please choose value for " + name + ": ", "Choose property", JOptionPane.QUESTION_MESSAGE, null, new String[]{"true","false"}, "true");
                if(value == null)
                    return;
            }
            else {
                value = getString("Enter property value for " + name + ":\n\nAllowed values:\n" + properties.get(name));
                if(value == null)
                    return;
            }
            addProperties(section, name, value);
            System.out.println(section + " " + " name " + " " + value);
        }
    }
}//GEN-LAST:event_cmdAddActionPerformed

private void cmdRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdRemoveActionPerformed
    if(listProperties.getSelectedIndex() == -1)
        return;
    
    ListModel currentModel = listProperties.getModel();
    String[] data = new String[currentModel.getSize()-1];
    int minus = 0;
    for(int i = 0; i < currentModel.getSize(); i++) {
        if(!((String)currentModel.getElementAt(i)).equals(listProperties.getSelectedValue().toString()))
            data[i-minus] = (String) currentModel.getElementAt(i);
        else
            minus = 1;
     }
            
    JList newModel = new JList(data);
    listProperties.setModel(newModel.getModel());
}//GEN-LAST:event_cmdRemoveActionPerformed

private void jLabel14MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel14MouseClicked
    BrowserControl.openUrl(Constants.DOSBOX_CONFIG_URL);
}//GEN-LAST:event_jLabel14MouseClicked

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
    String label = JOptionPane.showInputDialog(this, "Please enter a label for the CD-ROM drive",dos.getCdromLabel());
    if(label != null)
        dos.setCdromLabel(label);
}//GEN-LAST:event_jButton5ActionPerformed

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
    String ikon = appIcon.getText();
    File fil = new File(ikon);
    int width = Main.pref.getIconWidth();
    String ext = "";
    if(width <=16)
        ext="-16";
    else if(width >= 17 && width <= 24)
        ext="-24";
    else
        ext="-32";
    
    String path = Constants.IMAGE_FOLDER + "gameIcons/application-x-executable" + ext + ".png";
    ImageIcon ii = new ImageIcon(getClass().getResource(path));
   
    if(fil.exists()) {
        if(ikon.toLowerCase().endsWith("ico")) { // If the file is a ICO file
            try {
                ImageInputStream in = ImageIO.createImageInputStream(new FileInputStream(new File(ikon)));
                ICOFile f;
                f = new ICOFile(in);
                IconEntry ie = f.getEntry(0);
                ii = new ImageIcon(ie.getBitmap().getImage());
            } catch (IOException ex) {
                System.out.println("Error reading icon " + ikon);
            }
        }
        else
            ii = new ImageIcon(ikon);

        JLabel Icon = new JLabel("");
        Icon.setIcon(ii);
        JOptionPane.showMessageDialog(this, Icon, "Preview", JOptionPane.PLAIN_MESSAGE);
    }
}//GEN-LAST:event_jButton6ActionPerformed

private void sldCyclesMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sldCyclesMousePressed
    if(evt.getClickCount() == 2) {
        String numberAsString = JOptionPane.showInputDialog(this, "Please enter the amount of instructions DOSBox should try to emulate each millisecond:",sldCycles.getValue());
        try {
            int number = Integer.parseInt(numberAsString);

            if(number > sldCycles.getMaximum())
                sldCycles.setMaximum(number);
            if(number < 0)
                return;
            sldCycles.setValue(number);
            sldCycles.setPaintLabels(true);
            sldCycles.setPaintLabels(false);
            sldCycles.repaint();
        }
        catch(NumberFormatException e) {
            JOptionPane.showMessageDialog(this, "Invalid number.");
        }
    }
}//GEN-LAST:event_sldCyclesMousePressed

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
    String filename = appPath.getText() + "/" + appExec.getText();
    if(appPath.getText().endsWith("/") || appPath.getText().endsWith("\\"))
        filename = appPath.getText() + appExec.getText();
    
    String hash = TrubenResource.getMD5(filename);
    TrubenResource or = new TrubenResource(hash);

    System.out.println("-" + hash);
    
    if(or.isValid()) {
        appName.setText(or.getName());
        cmbGenre.setSelectedItem(or.getGenre());
        cmbYear.setSelectedItem(or.getYear());
        txtDeveloper.setText(or.getDeveloper());
        txtPublisher.setText(or.getPublisher());
    }
    else {
        JOptionPane.showMessageDialog(this, "Sorry, no entry found!");
    }

}//GEN-LAST:event_jButton7ActionPerformed

private void txtDeveloperActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDeveloperActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event_txtDeveloperActionPerformed

private void cdromDriveLetterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cdromDriveLetterActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event_cdromDriveLetterActionPerformed

    private void addProperties(String section, String property, String value) {
        ListModel currentModel = listProperties.getModel();
        String[] data = new String[currentModel.getSize()+1];
        for(int i = 0; i < currentModel.getSize(); i++)
            data[i] = (String) currentModel.getElementAt(i);
        
        if(value == null)
            data[data.length-1] = section + " => " + property;
        else
            data[data.length-1] = section + " => " + property + " = " + value;

        Arrays.sort(data);
        JList newModel = new JList(data);
        listProperties.setModel(newModel.getModel());
    }

    private String getString(String msg) {
        return JOptionPane.showInputDialog(msg, "");
    }

     private ImageIcon resizeIcon(ImageIcon icon) {
         if(Main.pref.isIconResize()) {
             int width = 32;
             int height = 32;

             BufferedImage bi = new BufferedImage(width, height,
             BufferedImage.TYPE_INT_ARGB);
             bi.getGraphics().drawImage(icon.getImage(), 0, 0, width, height, null);

             return new ImageIcon(bi);
         }
         else
             return icon;
     }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField appCD;
    private javax.swing.JTextField appExec;
    private javax.swing.JSpinner appFrameSkip;
    private javax.swing.JTextField appIcon;
    private javax.swing.JTextField appName;
    private javax.swing.JTextField appPath;
    private javax.swing.JTextField appSetup;
    private javax.swing.JComboBox cdromDriveLetter;
    private javax.swing.JCheckBox chkFavorite;
    private javax.swing.JComboBox cmbGenre;
    private javax.swing.JComboBox cmbYear;
    private javax.swing.JButton cmdAdd;
    private javax.swing.JButton cmdConfirm;
    private javax.swing.JButton cmdRemove;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JList listProperties;
    private javax.swing.JSlider sldCycles;
    private javax.swing.JTextField txtDeveloper;
    private javax.swing.JTextField txtKeywords;
    private javax.swing.JTextField txtPublisher;
    // End of variables declaration//GEN-END:variables

    @Override
    public void dispose() {
        cmdConfirmActionPerformed(null);
    }


}